<?php
ob_start();
require_once '../sub/init.php';
if(@!in_array('huxuan',$navarr))exit('该功能已关闭');
if(is_weixin() && empty($cook_openid)){
	$cook_openid = wx_get_openid();
	setcookie("cook_openid",$cook_openid,time()+31536000,"/",$_ZEAI['CookDomain']);
}
require_once ZEAI.'sub/conn.php';
$id=intval($id);
$row = $db->ROW(__TBL_HUXUAN__,"*","id=".$id." AND flag>0","name");
if ($row){
	$title        = trimhtml(dataIO($row['title'],'out'));
	$content      = dataIO($row['content'],'out');
	$path_s       = $row['path_s'];
	$flag         = $row['flag'];
	$jzbmtime     = $row['jzbmtime'];
	$hxtime       = $row['hxtime'];
	$bmtj_data    = $row['bmtj_data'];$bmtj_data_ARR = explode(',',$bmtj_data);
	$bmtj_data_bfb_num = $row['bmtj_data_bfb_num'];
	$bmtj_data_px = $row['bmtj_data_px'];
	$ifadmlist    = $row['ifadmlist'];
	$wxshareT     = dataIO($row['wxshareT'],'wx');
	$wxshareC     = dataIO($row['wxshareC'],'wx');
	$privateC     = dataIO($row['privateC'],'out');
	$json_hxnum   = $row['json_hxnum'];
	$json_price   = json_decode($row['json_price'],true);
	if(empty($submitok)){
		if($flag==1 && $jzbmtime<ADDTIME){
			$db->query("UPDATE ".__TBL_HUXUAN__." SET flag=2 WHERE id=".$id);
			$flag=2;
		}
		$db->query("UPDATE ".__TBL_HUXUAN__." SET click=click+1 WHERE id=".$id);
	}
	$ifbm = hx_ifbm($id,$cook_uid);
	switch ($flag) {
		case -1:$flag_str = '已隐藏';break;
		case 1:$flag_str  = '火热报名中';break;
		case 2:$flag_str  = '报名已结束-互选进行中';break;
		case 3:$flag_str  = '活动已结束';break;
	}
	$hxid=$id;
}else{
	alert('亲，该活动跑路了~',HOST);
}
$jumpurl = HOST.'/m/huxuan_detail.php?id='.$id;
switch ($submitok) {
	case 'ajax_iMarquee':
		$SQL = " a.uid=c.senduid AND a.senduid=c.uid AND a.uid=U.id AND c.fid=".$id;
		$rt = $db->query("SELECT a.uid,a.senduid FROM ".__TBL_HUXUAN_HXU__." a,".__TBL_USER__." U,".__TBL_HUXUAN_HXU__." c WHERE ".$SQL." ORDER BY a.id DESC LIMIT 15");
		$total = $db->num_rows($rt);
		$c = '';
		if ($total>0){
			for($i=1;$i<=$total;$i++) {
				$rows = $db->fetch_array($rt,'name');
				if(!$rows) break;
                $uid = $rows['uid'];
                $senduid = $rows['senduid'];
                $uid     = '*'.substr($uid,1,3).'*'.substr($uid,4,1).'*';
                $senduid = '*'.substr($senduid,1,3).'*'.substr($senduid,4,1).'*';
                $c.= '<li><font>恭喜会员</font> <font>'.$uid.'</font> 与 <font>'.$senduid.'</font> <font>互选成功</font></li>';
			}
		}
		exit($c);
	break;
	case 'ajax_private':
		json_exit(array('flag'=>1,'c'=>$privateC));
	break;
	case 'bm':
		if($jzbmtime<ADDTIME || $flag!=1){
			if($js==1){
				json_exit(array('flag'=>0,'msg'=>'亲，报名时间已过期，请进入互选大厅！'));
			}else{
				zeaialert('{"title":"亲，报名时间已过期，请进入互选大厅！","btnt":"我知道了","url":"-1"}');	
			}
		}
		$currfields = "sex,grade,RZ,myinfobfb,photo_f,nickname";
		require_once ZEAI.'m/my_chk_u.php';
		$cook_nickname = trimhtml(dataIO($row['nickname'],'out'));
		$cook_sex   = $row['sex'];
		$cook_grade = $row['grade'];
		$cook_photo_f = $row['photo_f'];
		$cook_RZ    = $row['RZ'];$cook_RZarr = explode(',',$cook_RZ);
		$cook_myinfobfb = intval($row['myinfobfb']);
		if ($ifbm){
			if($js==1){
				json_exit(array('flag'=>0,'msg'=>'亲，您已经报过名了，请等待互选！<br>开始时间【'.YmdHis($hxtime).'】'));
				json_exit(array('flag'=>'starthx','msg'=>'亲，您已经报过名了，请进入互选！'));
			}else{
				zeaialert('{"title":"亲，您已经报过名了，请等待互选！<br>互选开始时间【'.YmdHis($hxtime).'】","btnt":"我知道了","url":"-1"}');	
				zeaialert('{"title":"亲，您已经报过名了，请进入互选！","btnt":"我知道了","url":"huxuan_detail_ulist.php?id='.$id.'"}');	
			}
		}
		//会员级别有无报名资格：互选人数不为0
		$json_hxnum    = json_decode($json_hxnum,true);
		$my_json_hxnum = intval($json_hxnum[$cook_grade]);
		if($my_json_hxnum<=0){
			if($js==1){
				json_exit(array('flag'=>0,'msg'=>'亲，您所在的会员级别不能参加此活动'));
			}else{
				zeaialert('{"title":"亲，您所在的会员级别不能参加此活动","btnt":"我知道了","url":"-1"}');	
			}
		}
		$mybmprice = $json_price[$cook_sex.'_'.$cook_grade];
		//前置条件
		$json=array("ARR"=>$bmtj_data_ARR,"jumpurl"=>$jumpurl,"RZarr"=>$cook_RZarr,"cook_sex"=>$cook_sex,"cook_grade"=>$cook_grade,"cook_photo_f"=>$cook_photo_f,"cook_myinfobfb"=>$cook_myinfobfb,"data_bfb_num"=>$bmtj_data_bfb_num,"js"=>$js);
		Before_TJ(encode_json($json));
		if($mybmprice==0){
			$db->query("INSERT INTO ".__TBL_HUXUAN_BMU__."  (fid,addtime,uid) VALUES ($id,".ADDTIME.",$cook_uid)");
			//通知红娘
			tell_hn($ifadmlist,'【互选相亲】→【'.$title.'】','报名用户（'.$cook_nickname.'，UID：'.$cook_uid.'），免费报名',$jumpurl);
			if($js==1){
				json_exit(array('flag'=>1,'msg'=>'报名成功！'));
			}else{
				zeaialert('{"title":"报名成功！","btnt":"返回活动首页","url":"'.$jumpurl.'"}');
			}
		}else{
			if($js==1){
				json_exit(array('flag'=>1,'msg'=>'验证通过，开始支付'));
			}else{
				zeaialert('{"title":"此活动需要缴纳报名费￥'.$mybmprice.'元，请刷新活首页进行报名支付","btnt":"我知道了","url":"-1"}');
			}
		}
	break;
}
$kf_tel=dataIO($_ZEAI['kf_tel'],'out');$kf_mob=dataIO($_ZEAI['kf_mob'],'out');$kf_wxpic=dataIO($_ZEAI['kf_wxpic'],'out');?>
<!doctype html><html><head><meta charset="utf-8">
<title><?php echo $title;?> - <?php echo $_ZEAI['siteName'];?></title>
<?php echo HEADMETA;?>
<meta name="generator" content="Zeai.cn HUXUAN1.1" />
<link href="<?php echo RES;?>m/css/m.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<link href="<?php echo RES;?>m/css/huxuan_detail.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<link href="<?php echo HOST;?>/cache/zeaicolor.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<script src="<?php echo RES;?>www_zeai_cn.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo RES;?>m/js/m.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo RES;?>m/js/huxuan_detail.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script>var pH=<?php echo (is_weixin())?30.5:37.5;?>,id=<?php echo $id;?></script>
<?php
if (is_weixin()){
	require_once ZEAI."api/weixin/jssdk.php";?>
	<script src="<?php echo RES; ?>jweixin-1.2.0.js"></script>
	<script>
	wx.config({debug:false,appId: '<?php echo $signPackage["appId"];?>',timestamp: <?php echo $signPackage["timestamp"];?>,nonceStr:'<?php echo $signPackage["nonceStr"];?>',signature: '<?php echo $signPackage["signature"];?>',jsApiList:['hideMenuItems','onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareWeibo','previewImage']});
	var FX_title = '<?php echo $wxshareT;?>',
	FX_desc  = '<?php echo trimhtml($wxshareC).'【'.$_ZEAI['siteName'].'】';?>',
	FX_link  = '<?php echo $jumpurl; ?>',
	  FX_imgurl= '<?php echo UP.smb($path_s,'b'); ?>';
	wx.ready(function () {
		wx.onMenuShareAppMessage({title:FX_title,desc:FX_desc,link:FX_link,imgUrl:FX_imgurl});
		wx.onMenuShareTimeline({title:FX_title,link:FX_link,imgUrl:FX_imgurl});
	});
	</script>
<?php }?>
<style>
.hx_top:after,.HONG,.hx_i_btm a:last-child span,.hx_detail_BN{background-color:<?php echo $_ZEAI['mob_mbcolor'];?>}
.hx_nav a.ed span{color:<?php echo $_ZEAI['mob_mbcolor'];?>}
.hx_top:before{background-image:url("<?php echo RES;?>m/img/my_bg.png");}
.hx_nav a.ed i{background-color:<?php echo $_ZEAI['mob_mbcolor'];?>}
#backtop a{background-color:#fff;color:<?php echo $_ZEAI['mob_mbcolor'];?>}
#djsbox{display:block;font-size:1.3rem}
#djsbox span{margin:0 .5rem}
#djsbox font{width:2rem;background-color:rgba(0,0,0,0.4);color:#fff;padding:0 .4rem;border-radius:.2rem}
#djsbox i{margin-right:.4rem}
.hx_private .C .agreebox button:first-child{background-color:#fff;border:1px solid <?php echo $_ZEAI['mob_mbcolor'];?>;color:<?php echo $_ZEAI['mob_mbcolor'];?>}
.hx_private .C .agreebox button:last-child{background-color:<?php echo $_ZEAI['mob_mbcolor'];?>;border-color:<?php echo $_ZEAI['mob_mbcolor'];?>;color:#fff}
.iMarqueeBox{background-color:rgba(<?php echo c16_rgb($_ZEAI['mob_mbcolor']);?>,.05)}
.iMarqueeBox h5{background-color:rgba(<?php echo c16_rgb($_ZEAI['mob_mbcolor']);?>,.7)}
</style>
</head><body>
<?php 
$mini_title='【'.$flag_str.'】';
switch ($flag){ 
	case 1:
		if(ADDTIME < $jzbmtime){//报名中
			$djs_difftime=$jzbmtime-ADDTIME;
			$mini_title = "<div id='djsbox' diftime=".$djs_difftime."><i class='ico'>&#xe634; 报名倒计时</i><font>00</font><span>时</span><font>00</font><span>分</span><font>00</font><span>秒</span></div>";
		}else{
			$mini_title = "【火热报名中】";
		}
	break;
	case 2:
		if(ADDTIME<$hxtime){//等待互选
			$djs_difftime=$hxtime-ADDTIME;
			$mini_title = "<div id='djsbox' diftime=".$djs_difftime."><i class='ico'>&#xe634; 距互选还剩</i><font>00</font><span>时</span><font>00</font><span>分</span><font>00</font><span>秒</span></div>";
		}else{
			$mini_title = "<b>【互选进行中】</b>";
		}
	break;
	case 3:echo $mini_title="【活动已结束】";break;
}
$mini_class='top_mini4 zeaibg bgcolor';
$mini_L = '<em onClick="zeai.back()"><i class="ico" >&#xeaca;</i></em>';
require_once ZEAI.'m/top_mini.php';
$bmnum = $db->COUNT(__TBL_HUXUAN_BMU__,"fid=".$id);
if(($flag==1 && $jzbmtime>ADDTIME ) || $flag==2 && $hxtime>ADDTIME){?>
    <script>
        var B = o('djsbox').getElementsByTagName('font');
        var Hid = B[0],Mid=B[1],Sid=B[2];
        var diftime = o('djsbox').getAttribute("diftime");
        hx_djs(Hid,Mid,Sid,diftime);
    </script>
<?php }?>
<?php if (!empty($path_s)){?><div class="hx_detail_BN"><img src="<?php echo UP.smb($path_s,'b');?>"></div><?php }?>
<div class="hx_top">
    <div class="hx_ilist">
    	<h1><?php echo $title;?></h1>
		<dl><dt class="zeaicolor"><i class="ico">&#xe638;</i>本期参与嘉宾</dt><dd><i class="ico zeaicolor">&#xe643; <b><?php echo $bmnum;?>人</b></i>已参与</dd></dl>
        <div class="clear"></div>
		<ul>
            <?php
			if($bmnum>0){
				$rt=$db->query("SELECT U.sex,U.photo_s,U.photo_f,U.photo_ifshow,U.flag AS uflag FROM ".__TBL_HUXUAN_BMU__." a,".__TBL_USER__." U WHERE a.uid=U.id AND a.fid=".$id." ORDER BY a.id DESC LIMIT 38");
				$total = $db->num_rows($rt);
				if ($total > 0) {
					for($i=1;$i<=$total;$i++) {
						$rows = $db->fetch_array($rt,'name');
						if(!$rows) break;
						$uid      = $rows['id'];
						$sex      = $rows['sex'];
						$photo_s  = $rows['photo_s'];
						$photo_f  = $rows['photo_f'];
						$photo_ifshow = $rows['photo_ifshow'];
						$uflag = $rows['uflag'];
						$photo_s_url=photo_s_out('{"smb":"s","sex":"'.$sex.'","photo_s":"'.$photo_s.'","photo_f":"'.$photo_f.'","photo_ifshow":"'.$photo_ifshow.'","uflag":"'.$uflag.'","outkind":"url"}');	
						echo '<li><img src="'.$photo_s_url.'"></li>';
					}
					echo '<li class="more"><i class="ico">&#xe642;</i></li>';
				}
			}else{
				echo '<div class="nodata"><i class="ico">&#xe659;</i>暂时还没有人报名</div>';
			}
			?>
        </ul>
        <div class="clear"></div>
		<?php 
		$rt2 = $db->query("SELECT a.id FROM ".__TBL_HUXUAN_HXU__." a,".__TBL_USER__." U,".__TBL_HUXUAN_HXU__." c WHERE a.uid=c.senduid AND a.senduid=c.uid AND a.uid=U.id AND c.fid=".$id);
		$total2 = $db->num_rows($rt2);
		if ($total2>0){?> 
        <div class="iMarqueeBox">
            <h5>成功<?php echo intval($total2/2);?>对</h5>
            <div id="iMarquee" class="iMarquee">
                <li>互选成功会员载入中...</li>
            </div>
        </div>
        <script>setTimeout(function(){zeai_iMarqueeFn();},2000);</script>
        <?php }?>
    </div>
</div>
<?php if (str_len($content)>5){?><div class="hx_detail_C"><?php echo $content;?></div><?php }?>
<div id="hx_weixin_ewmBox" class="my-subscribe_box" style="display:none"><img src="<?php echo UP.$kf_wxpic;?>"><h3>长按二维码添加客服微信</h3></div>
<div class="hx_i_btm">
    <a href="tel:<?php echo $kf_tel;?>" class="zeaicolor"><i class="ico">&#xe7c1;</i><span>幸福热线</span></a>
    <a onClick="ZeaiM.div({obj:hx_weixin_ewmBox,w:26,h:26});" class="zeaicolor"><i class="ico">&#xe784;</i><span>咨询客服</span></a>
    <?php
	if ($ifbm){
		if($flag==3){	
			echo '<a><span class="off">活动已结束</span></a>';
		}else{
			echo '<a href="'.HOST.'/m/huxuan_detail_ulist.php?id='.$id.'"><span>进入互选大厅</span></a>';
		}
	}else{
		if(ifint($cook_uid)){
			$row = $db->ROW(__TBL_USER__,"sex,grade,money","id=".$cook_uid,"name");
			if ($row){
				$cook_sex   = $row['sex'];
				$cook_grade = $row['grade'];
				$cook_money = $row['money'];
			}else{ZEclearcookAI_CN();callmsg('库里无记录',mHref('login').'?jumpurl='.$jumpurl);}
			$mybmprice = $json_price[$cook_sex.'_'.$cook_grade];
			if($mybmprice==0){
				echo '<a href="'.HOST.'/m/huxuan_detail.php?id='.$id.'&submitok=bm"><span>立即报名</span></a>';
			}else{
				$jump_url = $jumpurl;
				$money = $mybmprice;
				$kind  = 13;
				echo '<input type="hidden" id="money" value="'.$money.'">';
				echo '<a onClick="paybtnFn('.$id.')"><span>立即报名</span></a>';
				$ifpaybox=true;
			}
		}else{
			echo '<a href="'.HOST.'/m/huxuan_detail.php?id='.$id.'&submitok=bm"><span>立即报名</span></a>';
		}
	}
	?>
</div>
<?php if($ifpaybox){require_once 'my_pay.php';}?>
<?php if (is_weixin() && ifint($cook_uid)){wx_endurl('您刚刚浏览的页面【互选相亲】',$jumpurl);}?>
<?php
if (!empty($privateC) && str_len($privateC)>10){?>
    <div class="hx_private" id="hx_private">
        <div class="C">
            <h1>《活动隐私与用户协议》提示</h1><em id="hx_privateC"></em>
            <div class="agreebox"><button class="btn size4 FL" type="button" onClick="index_privateFn(0)">不同意</button>
            <button class="btn size4 FR" type="button" onClick="index_privateFn(1)">同意</button></div>
        </div>
    </div>
    <script>
    if(zeai.empty(localStorage.hx_private)){
        setTimeout(function(){zeai.ajax({url:MHOST+'/huxuan_detail'+zeai.extname,data:{id:<?php echo intval($hxid);?>,submitok:'ajax_private'}},function(e){var rs=zeai.jsoneval(e);
            if(rs.flag==1){zeai.mask({son:hx_private,cancelBubble:'off'});hx_privateC.html(html_decode(rs.c));}
        });},500);
        function index_privateFn(k){if(k==1){localStorage.hx_private='WWWzeaiCN_hx_private';}o('Mhx_private').parentNode.removeChild(o('Mhx_private'));}
    }
    </script>
    <?php 
}?>
<div id="backtop"><a id="btmTopBtn" onClick="zeai.setScrollTop(0);"><i class="ico">&#xe60c;</i>顶部</a></div>
<script>function backtopFnn(){backtopFn();}document.body.onscroll = backtopFnn;</script>
<?php require_once ZEAI.'m/TRnav.php';?>
</body></html>
<?php
function hx_ifbm($id,$cook_uid) {
	global $db;
	if(!ifint($id) || !ifint($cook_uid) )return false;
	if($db->ROW(__TBL_HUXUAN_BMU__,"id","fid=".$id." AND uid=".$cook_uid))return true;
	return false;
}
ob_end_flush();
?>